{% extends "layout/basic.html" %}
{% block content %}
<div class="row">
  <div class="medium-9 columns">
    <div class="section">
      <div class="section__header">
        <h1 class="section__title">{{ _('Dataset') }}</h1>
      </div>
      <div class="section__body">
        <iframe src="{{ reverse_url('problem_upload', pid=pdoc['doc_id']) }}" frameborder="0" style="width: 100%; height: 100px;"></iframe>
        <p class="help-text">{{ _('Hint') }}: <a href="{{ reverse_url('wiki_help') }}#upload">{{ _('Dataset Format') }}</a>, {{ _('An example of dataset') }}: <a href="https://github.com/vijos/jd4/blob/master/jd4/testdata/aplusb-legacy.zip?raw=true">{{ _('Download') }}</a></p>
        {% if pdoc and (handler.own(pdoc, vj4.model.builtin.PERM_READ_PROBLEM_DATA_SELF) or handler.has_perm(vj4.model.builtin.PERM_READ_PROBLEM_DATA) or handler.has_priv(vj4.model.builtin.PRIV_READ_PROBLEM_DATA)) %}
        <p><a href="{{ reverse_url('problem_data', pid=pdoc['doc_id']) }}" class="expanded button">{{ _('Download Dataset') }}</a></p>
        {% endif %}
      </div>
    </div>
    <div class="section">
      <div class="section__header">
        <h1 class="section__title">{{ _('Settings') }}</h1>
      </div>
      <div class="section__body">
        <form method="post">
          {{ form.form_checkbox(label='Hidden', help_text='Note: Problem title may not be hidden.', name='hidden', value=pdoc['hidden']) }}
          {{ form.form_text(columns=12, label='Category', help_text='Format: category 1, sub category 1.1, sub category 1.2, ..., sub category 1.x, ..., category n, sub category n.1, sub category n.2, ..., sub category n.m, ...', name='category', value=pdoc['category']|join(', ')) }}
          {{ form.form_text(columns=12, label='Tags', help_text='Splitted by \', \'.', name='tag', value=pdoc['tag']|join(', ')) }}
          {{ form.form_text(columns=12, label='AC Message', help_text='This message will be presented to those whose submissions are accepted.', name='ac_msg', value=(pdoc['ac_msg'] or '' )) }}
          <div class="row">
            {{ form.form_select(columns=4, label='Difficulty', name='difficulty_setting', options=vj4.model.adaptor.problem.SETTING_DIFFICULTY_RANGE.items(), value=pdoc['difficulty_setting']|default(0), row=false) }}
            {{ form.form_text(columns=4, label='Evaluated difficulty', help_text='Effects only when Difficulty is not \'Use algorithm calculated\'.', name='difficulty_admin', placeholder='9', value=pdoc['difficulty_admin'] or '', row=False) }}
            <div class="medium-4 columns">
              <p class="help-text">{{ _('Difficulty displayed') }}: {{ pdoc['difficulty'] or _('(None)') }}</p>
              <p class="help-text">{{ _('Difficulty by algorithm') }}: {{ pdoc['difficulty_algo'] or _('(None)') }}</p>
              <p class="help-text">{{ _('Difficulty by admin') }}: {{ pdoc['difficulty_admin'] or _('(None)') }}</p>
            </div>
          </div>
          <div class="row"><div class="columns">
            <input type="hidden" name="csrf_token" value="{{ handler.csrf_token }}">
            <button type="submit" class="rounded primary button">
              {{ _('Update') }}
            </button>
            <button type="button" class="rounded button" onclick="window.history.go(-1)">
              {{ _('Cancel') }}
            </button>
          </div></div>
        </form>
      </div>
    </div>
    <div class="section side">
      <div class="section__header">
        <h1 class="section__title">{{ _('Categories') }} ({{ _('click to add') }})</h1>
      </div>
      <div class="section__body">
      <!-- TODO: chip -->
      {% for category, sub_categories in categories.items() %}
        <div>
          <h2 class="section__title"><a class="category-a" href="javascript:;" data-category="{{ category }}">{{ category }}</a></h2>
          <ol>
          {% for sub_category in sub_categories %}
            <li><a class="category-a typo-a" href="javascript:;" data-category="{{ sub_category }}">{{ sub_category }}</a></li>
          {% endfor %}
          </ol>
        </div>
      {% endfor %}
      </div>
    </div>
  </div>
  <div class="medium-3 columns">
    {% with owner_udoc=udoc, owner_dudoc=dudoc %}
    {% include "partials/problem_sidebar.html" %}
    {% endwith %}
  </div>
</div>
{% endblock %}
